﻿using System.Configuration;
using System.Data;
using Microsoft.ApplicationBlocks.Data;

namespace Core.AdminUser
{
    public class AdminUserDAL
    {
        private static readonly string _conn = ConfigurationManager.ConnectionStrings["EventConnectionString"].ToString();

        public static bool AdminUser_Validate(string username, string password, int statuses)
        {
            return (int)SqlHelper.ExecuteScalar(_conn, "AdminUser_ValidateUser", username, password, statuses) == 1;
        }

        public static int AdminUser_Create(AdminUserObject o)
        {
            return (int) SqlHelper.ExecuteScalar(_conn, "AdminUser_Create", o.Username, o.Password, o.Email, o.FullName,
                                                                            o.Birthday, o.Gender, o.Information, o.Status, 
                                                                            o.CreatedOn, o.ModifiedOn, o.LastLoggedOn);
        }

        public static void AdminUser_Update(AdminUserObject o)
        {
            SqlHelper.ExecuteNonQuery(_conn, "AdminUser_Update", o.AdminUserId, o.Email, o.FullName, o.Birthday,
                                                                 o.Gender, o.Information, o.Status);
        }

        public static void AdminUser_UpdateInfomation(AdminUserObject o)
        {
            SqlHelper.ExecuteNonQuery(_conn, "AdminUser_UpdateInfomation", o.AdminUserId, o.Email, o.FullName, o.Birthday,
                                                                 o.Gender, o.Information);
        }

        public static void AdminUser_UpdatePassword(int userId, string pass)
        {
            SqlHelper.ExecuteNonQuery(_conn, "AdminUser_UpdatePassword", userId, pass);
        }

        public static bool AdminUser_CheckIfUserExisted(string username)
        {
            return (int)SqlHelper.ExecuteScalar(_conn, "AdminUser_CheckIfUserExisted", username) != 0;
        }

        public static IDataReader AdminUser_GetById(int adminUserId)
        {
            return SqlHelper.ExecuteReader(_conn, "AdminUser_GetById", adminUserId);
        }

        public static IDataReader AdminUser_GetBy_Username_Status(string username, int status)
        {
            return SqlHelper.ExecuteReader(_conn, "AdminUser_GetBy_Username_Status", username, status);
        }

        public static IDataReader AdminUser_GetAllByStatuses(int statuses)
        {
            return SqlHelper.ExecuteReader(_conn, "AdminUser_GetAllByStatuses", statuses);
        }

        public static IDataReader AdminUser_GetAllByStatusesByAdminGroupId(int adminGroupId, int statuses)
        {
            return SqlHelper.ExecuteReader(_conn, "AdminUser_GetAllByStatusesByAdminGroupId", adminGroupId, statuses);
        }
    }
}